<?php
class FloorBrandModel extends BaseModel
{
    public function getList($mid = null, $fid = null, $bid = null)
    {
        if (intval($mid)) {
            $map['mid'] = $mid;
        }
        if (intval($fid)) {
            $map['fid'] = $fid;
        }
        if (intval($bid)) {
            $map['bid'] = $bid;
        }
        return $this->getListByWhere($map, 'id, mid, fid, bid');
    }

    public function getOne($id)
    {
        $map['id'] = intval($id);
        return $this->getByWhere($map, 'id, mid, fid, bid');
    }

    /**
     * 获取商场旗下品牌数量
     * @param int $mid
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getMallBrandCount($mid)
    {
        $map = array();
        $map['mid'] = $mid;
        return $this->where($map)->count();
    }

    /**
     * 获取品牌搜索柜台信息
     * @param array $map
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getSearchBrand($map)
    {
        $data = array();
        $data = $this->field(
            'm_floor_brand.*,
				m_market.initial,
				m_market.name as mall_name,
				m_floor.sain as floor_sain,
				m_floor.name as floor_name,
				m_brand.name as brand_name,
				m_brand.ename as brand_ename')
            ->where($map)
            ->join('m_market ON m_floor_brand.mid = m_market.id')
            ->join('m_floor ON m_floor_brand.fid = m_floor.id')
            ->join('m_brand ON m_floor_brand.bid = m_brand.id')
            ->select();
        foreach ($data as $k => $v) {
            $data[$k]['ad_url'] = strtolower(U('/' . $v['initial'] . '/' . strtolower($v['floor_sain']) . '/' . $v['brand_ename']));
        }
        return $data;
    }

    /**
     * 获取楼层旗下品牌
     * @param $map
     * @param null $limit
     * @return array|mixed
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getFloorBrand($map, $limit = null)
    {
        $data = array();
        $data = $this->field(
            'm_floor_brand.id,m_floor_brand.mid,m_floor_brand.fid,m_floor_brand.bid,m_brand.name,m_brand.image,m_brand.small_image,m_brand.ename,m_floor.sain')
            ->where($map)
            ->limit($limit)
            ->join('INNER JOIN m_brand ON m_floor_brand.bid = m_brand.id')
            ->join('m_floor ON m_floor_brand.fid = m_floor.id')
            ->select();
        return $data;
    }
}

?>